package com.lsq.lwf.common.frame;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lsq.lwf.common.xmlparse.base.BaseXml;

public class BaseFrame extends BaseXml {

	
	public static void execute(ServletRequest req,ServletResponse res){
		
		HttpServletRequest request=(HttpServletRequest) req;
		HttpServletResponse response=(HttpServletResponse) res;
		
		
		String url = request.getRequestURL().toString();

		String methodName = url.substring(url.lastIndexOf("/") + 1,
				url.lastIndexOf("."));

		 HashMap<String, Method> methodMap=viewNamespaceMap.get("user-view");
		 
		 Iterator<Map.Entry<String, Method>> methodIter=methodMap.entrySet().iterator();
		 
		 while(methodIter.hasNext()){
			 Map.Entry<String,Method> entry=methodIter.next();
			 
			 if(entry.getKey().contains(methodName)){
				try {
					 Object obj=Class.forName(entry.getKey().split("-")[1]).newInstance();
					 String path=(String) entry.getValue().invoke(obj);
					 
					 String view=resultMap.get(path);
					 
//					 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+req.getContextPath();
//					 req.getRequestDispatcher(basePath+view).forward(req, res);
//					 res.sendRedirect(basePath+"/index.jsp");
					 request.getRequestDispatcher(view).forward(request, response);
					 return;
				} catch (Exception e) {
					e.printStackTrace();
				}
			 }
		 }
	}


}
